
package com.shop.cloud.mall.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.cloud.mall.admin.service.SeckillHallInfoService;
import com.shop.cloud.mall.common.entity.SeckillHallInfo;
import com.shop.cloud.mall.common.entity.SeckillInfo;
import com.shop.cloud.mall.admin.mapper.SeckillInfoMapper;
import com.shop.cloud.mall.admin.service.SeckillInfoService;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.klock.annotation.Klock;
import org.springframework.boot.autoconfigure.klock.model.LockTimeoutStrategy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;

/**
 * 秒杀商品
 *
 * @author
 * @date 2020-08-12 11:03:50
 */
@Service
@AllArgsConstructor
public class SeckillInfoServiceImpl extends ServiceImpl<SeckillInfoMapper, SeckillInfo> implements SeckillInfoService {

	private final SeckillHallInfoService seckillHallInfoService;

	@Override
	@Klock(name = "SeckillInfo", keys = {"#entity.getId()"}, lockTimeoutStrategy = LockTimeoutStrategy.FAIL_FAST)
	public boolean updateById(SeckillInfo entity) {
		return super.updateById(entity);
	}

	@Override
	@Klock(name = "SeckillInfo", keys = {"#updateWrapper.getEntity().getId()"}, lockTimeoutStrategy = LockTimeoutStrategy.FAIL_FAST)
	public boolean update(Wrapper<SeckillInfo> updateWrapper) {
		return super.update(updateWrapper);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	@Klock(name = "SeckillInfo", keys = {"#id"}, lockTimeoutStrategy = LockTimeoutStrategy.FAIL_FAST)
	public boolean removeById(Serializable id) {
		//先删除关联商品
		seckillHallInfoService.remove(Wrappers.<SeckillHallInfo>lambdaQuery()
				.eq(SeckillHallInfo::getSeckillInfoId,id));
		return super.removeById(id);
	}
}
